# -*- coding: utf-8 -*-

# @Time : 2020/7/4 17:26 
# @Author : dzzhyk
# @File : csv_merge.py 
# @Software: PyCharm

import csv

# 合并csv文件

ls = [
    '../tiantian-ac.csv',
    '../tiantian-dl.csv',
    '../tiantian-ns.csv',
    '../tiantian-tz.csv',
]

def merge_list(lis):
    ss = ""
    for i in lis:
        ss += i+","
    ss += "\n"
    return ss

def merge(ls, save_to):
    with open(save_to, "a", encoding="utf-8") as fout:
        for path in ls:
            fin = open(path, "r", encoding="gbk")
            reader = csv.reader(fin)
            result = list(reader)
            for line in result:
                fout.write(merge_list(line).replace(',\n', '\n'))
                fout.flush()
            fin.close()
        fout.close()


if __name__ == '__main__':
    merge(ls, "../tiantian.csv")